package 开始的算法算法入门8月.双指针;
// https://leetcode-cn.com/problems/squares-of-a-sorted-array/
public class 有序数组的平方0813 {
    public int[] sortedSquares(int[] nums) {
        int start=0,end=nums.length-1;
        int idx=nums.length-1;
        int newarray[]=new int[end+1];
        while(start<=end){
            int l=nums[start]*nums[start];
            int r=nums[end]*nums[end];
            if(l<r){
                newarray[idx--]=r;
                end--;

            }
            else
            {
                newarray[idx--]=l;
                start++;
            }
        }
        return newarray;
    }
}
